package com.hunk.time;

import com.hunk.time.model.CartRule;
import com.hunk.time.model.Fruit;
import com.hunk.time.model.FruitCart;
import com.hunk.time.model.FruitOrder;

import java.math.BigDecimal;

public class FruitShopping {

    public static void main(String[] args) {
        customA();
        customB();
        customC();
        customD();
    }


    private static void customA() {
        FruitCart fruitCart = new FruitCart();
        Fruit apple = new Fruit("apple", new BigDecimal(8));
        Fruit strawberry = new Fruit("strawberry", new BigDecimal(13));
        fruitCart.addFruitOrder(new FruitOrder(apple, 5))
                .addFruitOrder(new FruitOrder(strawberry, 10));
        BigDecimal bigDecimal = fruitCart.calTotalPrice();
        System.out.println("购买水果总价：" + bigDecimal + "元");
        assert bigDecimal.compareTo(BigDecimal.valueOf(170)) == 0 : "总价计算出错";
    }

    private static void customB() {
        FruitCart fruitCart = new FruitCart();
        Fruit apple = new Fruit("apple", new BigDecimal(8));
        Fruit strawberry = new Fruit("strawberry", new BigDecimal(13));
        Fruit mongo = new Fruit("mongo", new BigDecimal(20));
        fruitCart.addFruitOrder(new FruitOrder(apple, 5))
                .addFruitOrder(new FruitOrder(strawberry, 10))
                .addFruitOrder(new FruitOrder(mongo, 6));
        BigDecimal bigDecimal = fruitCart.calTotalPrice();
        System.out.println("购买水果总价：" + bigDecimal + "元");
        assert bigDecimal.compareTo(BigDecimal.valueOf(290)) == 0 : "总价计算出错";
    }


    private static void customC() {
        FruitCart fruitCart = new FruitCart();
        Fruit apple = new Fruit("apple", new BigDecimal(8));
        Fruit strawberry = new Fruit("strawberry", new BigDecimal(13));
        Fruit mongo = new Fruit("mongo", new BigDecimal(20));
        fruitCart.addFruitOrder(new FruitOrder(apple, 5))
                .addFruitOrder(new FruitOrder(strawberry, 10, new BigDecimal("0.8")))
                .addFruitOrder(new FruitOrder(mongo, 6));
        BigDecimal bigDecimal = fruitCart.calTotalPrice();
        System.out.println("购买水果总价：" + bigDecimal + "元");

        assert bigDecimal.compareTo(BigDecimal.valueOf(264.0)) == 0 : "总价计算出错";
    }

    private static void customD() {
        CartRule cartRule = new CartRule(new BigDecimal(100),new BigDecimal(10));
        FruitCart fruitCart = new FruitCart(cartRule);
        Fruit apple = new Fruit("apple", new BigDecimal(8));
        Fruit strawberry = new Fruit("strawberry", new BigDecimal(13));
        Fruit mongo = new Fruit("mongo", new BigDecimal(20));
        fruitCart.addFruitOrder(new FruitOrder(apple, 5))
                .addFruitOrder(new FruitOrder(strawberry, 10, new BigDecimal("0.8")))
                .addFruitOrder(new FruitOrder(mongo, 6));
        BigDecimal bigDecimal = fruitCart.calTotalPrice();
        System.out.println("购买水果总价：" + bigDecimal + "元");

        assert bigDecimal.compareTo(BigDecimal.valueOf(244.0)) == 0 : "总价计算出错";
    }
}
